package com.cookmenu.adapter;

import java.util.List;
import java.util.Map;

import net.tsz.afinal.FinalBitmap;

import com.cookmenu.activity.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 搜索菜谱的listview的Adapter
 * 
 * @author yinfeng
 * 
 */
public class LvSearchInfoAdapter extends BaseAdapter {
	private Context context;
	private List<Map<Object, Object>> list;

	public LvSearchInfoAdapter(Context context, List<Map<Object, Object>> list) {
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View view, ViewGroup arg2) {
		Holder holder;
		if (view == null) {
			view = LayoutInflater.from(context).inflate(
					R.layout.layout_lv_search_info, null);
			holder = new Holder();
			holder.tv_title = (TextView) view.findViewById(R.id.tv_title);
			holder.tv_tags = (TextView) view.findViewById(R.id.tv_tags);
			holder.iv_albums = (ImageView) view.findViewById(R.id.iv_albums);
			view.setTag(holder);
		} else {
			holder = (Holder) view.getTag();
		}
		holder.tv_title.setText(list.get(position).get("title").toString());
		holder.tv_tags.setText(list.get(position).get("tags").toString());
		FinalBitmap bitmap = FinalBitmap.create(context);
		bitmap.display(holder.iv_albums, list.get(position).get("albums")
				.toString(), 70, 70);
		return view;
	}

	class Holder {
		TextView tv_title;
		TextView tv_tags;
		ImageView iv_albums;
	}
}
